{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-03-12T14:27:59.104808Z",
     "start_time": "2020-03-12T14:27:58.414811Z"
    }
   },
   "outputs": [],
   "source": [
    "import torch\n",
    "import torch.nn as nn\n",
    "\n",
    "import random\n",
    "from PIL import Image\n",
    "\n",
    "from torchvision import transforms\n",
    "\n",
    "from captcha.image import ImageCaptcha"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-03-12T14:27:59.117806Z",
     "start_time": "2020-03-12T14:27:59.106808Z"
    }
   },
   "outputs": [],
   "source": [
    "from model.attention_ocr import OCR\n",
    "from utils.dataset import CaptchaDataset\n",
    "from utils.train_util import train_batch, eval_batch\n",
    "from utils.tokenizer import Tokenizer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-03-12T14:27:59.130807Z",
     "start_time": "2020-03-12T14:27:59.119815Z"
    }
   },
   "outputs": [],
   "source": [
    "img_width = 160\n",
    "img_height = 60\n",
    "max_len = 4\n",
    "\n",
    "nh = 512\n",
    "\n",
    "device = 'cpu'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-03-12T14:28:29.860808Z",
     "start_time": "2020-03-12T14:28:29.857806Z"
    }
   },
   "outputs": [],
   "source": [
    "chars = list('1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')\n",
    "gen = ImageCaptcha(img_width, img_height)\n",
    "n_chars = 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-03-12T14:28:43.527805Z",
     "start_time": "2020-03-12T14:28:30.510810Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Model feature size: 5 17\n"
     ]
    }
   ],
   "source": [
    "tokenizer = Tokenizer(chars)\n",
    "model = OCR(img_width, img_height, nh, tokenizer.n_token,\n",
    "                max_len + 1, tokenizer.SOS_token, tokenizer.EOS_token).to(device=device)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-03-12T14:28:48.045809Z",
     "start_time": "2020-03-12T14:28:46.259820Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<All keys matched successfully>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.load_state_dict(torch.load('./chkpoint/time_2020-03-12_22-26-09_epoch_30.pth'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-03-12T14:28:48.729813Z",
     "start_time": "2020-03-12T14:28:48.725811Z"
    }
   },
   "outputs": [],
   "source": [
    "img_trans = transforms.Compose([\n",
    "    transforms.ToTensor(),\n",
    "    transforms.Normalize(mean=[0.485, 0.456, 0.406], std=(0.229, 0.224, 0.225)),\n",
    "])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-03-12T14:29:45.064809Z",
     "start_time": "2020-03-12T14:29:45.046810Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAKAAAAA8CAIAAABuCSZCAAAZ1klEQVR4nO186XMcx5Xne5lZV3dXdwMgQeIgQYiiSIoUKEqijvCsbdGWYybGG1pHeBw7EdJ/th92x47YiFlPzCh2HOvV2PTMeNeWTIkHxJsiQZAEGgcBdFdVd2VlVubbDwWAEAniIiDSG/xFf+ijqvpl/SpfvjMxVQm8wJ8t/vHvf1q8+cnPfrnqAeJbFOYFthMqiy+N/rxn1xEAODbykcpi1wsfPwyLGayyuPi86kEv8BxCZXEcT4yPnRkaPh2GA08iDlOVbPDQF3jesJFp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KseOfr9lTdiJZ7G3l77XD8odsrsk2lUqw9kWRr4Vc/fUIXsYpTNrb37nV2Xvvp9c/5upz2mVEQEQpDSxnVr9fqBru7+lW04whG7e/fcuuUUFZWcM2stLKX8EcAuVdhzzrSOlY4gBs8Nv2o3fD9EVj146IeeW/W80HFDb1ujuatCLI82hIFjJz4qCnHH7/xO6zTPc4aWcyR4QIS5jom6EUGIkIC0ipWOZRoZw4Kg1/Pqa2yP9TSbEm7k3CWmNw0/qHQxfurtv24uNL4aPTM/f1crlekF1yl3dR8++daPl5VzASGcSti1a9dQqaQDn4xJlIq1WlxBiKjoaik281huu1AqViqOI3C96lcXG+VynSg8MPw9x6l6ftX3w2CbdhZ7HKvs+K6yWKlkKUFbaOM5hr+S8rvTU7f37D3leiERaBXfvPmPshNnSlRrb46c+KDetWfV/3iaTWO/tQ1npWxH0dytry93OgtxPBmUe0+MfLde7328OkCmicwilcWMWa3j8TtnVBZlWZxlca5jACAAsivC17RsrhYWDQCh44S5LSHUw+q+N978sKt7rWzp02BDO74jzAGAUnGRfC3KD5SKk3jizthv9+x5t1Id8LxwjZrZbbSwdg5KZVqrNI2tta7r+kG4bhOsUnHBrlLRSqZVFhXmeME0Llrmy6yjtZRlttOBnp6R9/7io77+wzs0qMX9ore2a69aUk2brTj5/w8rmb4zdkapKFtsPImQIS6xWxhfhRrPpO2k2N3z2nvf+biv/5UdEuypdnx/wesyXDd03bASglJFBdJDpotVruisWPZBrAWtSUqohAM7upn45nZ8f4GNY3lOFx+XtPTir8VUthY9L/T96nZt3/o4NrTj+wv8+WJDO76/wJ8vntM6hBfYLvw/Tuu6GtGeiOgAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<PIL.PngImagePlugin.PngImageFile image mode=RGB size=160x60 at 0x1BE8DCDFA48>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "content = [random.randrange(0, len(chars)) for _ in range(n_chars)]\n",
    "s = ''.join([chars[i] for i in content])\n",
    "d = gen.generate(s)\n",
    "d = Image.open(d)\n",
    "d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-03-12T14:29:46.053810Z",
     "start_time": "2020-03-12T14:29:45.981810Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2eJL-\n"
     ]
    }
   ],
   "source": [
    "model.eval()\n",
    "with torch.no_grad():\n",
    "    pred = model(img_trans(d).unsqueeze(0))\n",
    "    \n",
    "rst = tokenizer.translate(pred.squeeze(0).argmax(1))\n",
    "print(rst)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
